package cn.nosql.tools;

import cn.nosql.myservice.MyNoSqlService;
import cn.nosql.service.INoSql;
import org.h2.mvstore.MVMap;
import org.h2.mvstore.MVStore;
import org.junit.Test;

import java.util.Hashtable;

public class MyMapCase {

    public static MVStore getStore(String dbName)
    {
        String fileName = "/Users/chenfei/Documents/Java/SmartSql/my-db/target/classes/my_store.db";
        //FileUtils.delete(fileName);
        System.out.println(fileName);
        MVStore store = new MVStore.Builder().fileName(fileName).open();
        MVMap<String, Hashtable<String, String>> m = store.openMap("my_data");
        Hashtable<String, String> ht = m.get(dbName);
        store.close();

        MVStore.Builder builder = MyDefindCache.definDb(ht);
        return builder.open();
    }

    @Test
    public void create_db()
    {
        INoSql noSql = MyNoSqlService.getInstance().getNoSql();
        noSql.executeSqlQuery("{fileName: '/Users/chenfei/temp/my_tmp.db', name: 'dafu'}");
    }

    @Test
    public void get_data()
    {
        MVStore store = MyMapCase.getStore("dafu");
        MVMap<Integer, String> m = store.openMap("dafu_cache");
        System.out.println(m.get(1));
        store.close();
    }

    @Test
    public void get_data_1()
    {
        MVStore store = MyMapCase.getStore("dafu");
        MVMap m = store.openMap("dafu_cache");
        System.out.println(m.get("a"));
        store.close();
    }

    @Test
    public void put_data()
    {
        MVStore store = MyMapCase.getStore("dafu");
        MVMap<Integer, String> m = store.openMap("dafu_cache");
        m.put(1, "wudafu");
        store.commit();
        store.close();
    }

    @Test
    public void put_data_1()
    {
        MVStore store = MyMapCase.getStore("dafu");
        MVMap m = store.openMap("dafu_cache");
        m.put("a", "wudafu");
        store.commit();
        store.close();
    }
}

































